package com.xiang.consumer;

import com.xiang.config.DirectConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 路由模式
 *
 * @author: xiangtianlei
 * @Date: 2022-9-10
 */
@Component
public class Direct {

    Logger log = LoggerFactory.getLogger(Direct.class);

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(DirectConfig.DIRECT_QUEUE_NAME1),
            exchange = @Exchange(name = DirectConfig.EXCHANGE_DIRECT, type = ExchangeTypes.DIRECT),
            key = {"Red", "Blue"}
    ))
    public void listenerDirectQueueRB(String msg) {
        log.info(Arrays.toString(DirectConfig.DIRECT_QUEUES_RB) + "-路由模式监听到的消息为:" + msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(DirectConfig.DIRECT_QUEUE_NAME2),
            exchange = @Exchange(name = DirectConfig.EXCHANGE_DIRECT, type = ExchangeTypes.DIRECT),
            key = {"Blue"}
    ))
    public void listenerDirectQueueG(String msg) {
        log.info(Arrays.toString(DirectConfig.DIRECT_QUEUES_G) + "-路由模式监听到的消息为:" + msg);
    }
}
